package com.mdinic.blogovi.front.page.person;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import com.mdinic.blogovi.front.common.OddRowIndicator;
import com.mdinic.blogovi.front.common.SmallPersonPhoto;
import com.mdinic.blogovi.model.Person;

public class PersonTopPanel extends Panel {
    private static final long serialVersionUID = 1L;

    public PersonTopPanel(String id, List<Person> posts) {
        super(id);

        ListView<Person> list = new ListView<Person>("list", posts) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<Person> item) {

                item.add(new Label("serial", item.getIndex() + 1));

                PageParameters pageParameters = new PageParameters();
                pageParameters.add(PersonViewPage.URL_PARAM_NAME, item.getModelObject().getId());
                BookmarkablePageLink<PersonViewPage> personViewLink = new BookmarkablePageLink<PersonViewPage>(
                        "person_link", PersonViewPage.class, pageParameters);
                personViewLink.add(new Label(Person.NICKNAME, new PropertyModel<String>(item.getModelObject(),
                        Person.NICKNAME)));
                item.add(personViewLink);

                item.add(new SmallPersonPhoto("avatar", item.getModelObject()));

                item.add(new Label(Person.POSTED, new PropertyModel<String>(item.getModelObject(), Person.POSTED)));
                item.add(new Label(Person.PROMOTED, new PropertyModel<String>(item.getModelObject(), Person.PROMOTED)));

                item.add(new Label(Person.COMMENTS, new PropertyModel<String>(item.getModelObject(), Person.COMMENTS)));
                item.add(new Label(Person.VOTES, new PropertyModel<String>(item.getModelObject(), Person.VOTES)));
                item.add(new Label(Person.VOTES_RECEIVED, new PropertyModel<String>(item.getModelObject(),
                        Person.VOTES_RECEIVED)));

                item.add(new OddRowIndicator(item));
            }
        };

        add(list);
    }

}
